home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 101-125 / scopedisk122 / bassub / lists.sub < prev    next >
Text File  |  1995-03-19  |  2KB  |  121 lines

  1. ' LISTS - Single Linked List Module
  2. '
  3. REM GetOrderedPtr
  4. SUB GetOrderedPtr(head%,ListSize%,ListPtr%(1),RankPtr%(1))
  5.     STATIC i%
  6.     
  7.     RankPtr%(1)=head%
  8.     
  9.     FOR i%=2 TO ListSize%
  10.         RankPtr%(i%)=ListPtr%(i%-1)
  11.     NEXT i%
  12. END SUB
  13.  
  14. REM RevOrderedPtr
  15. SUB RevOrderedPtr(head%,ListSize%,ListPtr%(1),RankPtr%(1))
  16.     STATIC i%
  17.     
  18.     RankPtr%(ListSize%)=head%
  19.     
  20.     FOR i%=ListSize%-1 TO 1 STEP -1
  21.         RankPtr%(i%)=ListPtr%(RankPtr%(i%+1))
  22.     NEXT i%
  23. END SUB
  24.  
  25. REM FindNode
  26. SUB FindNode(Item$,head%,ListItem$(1),ListPtr%(1),Found%)
  27. ' Search for Item$ in list ListItems$() starting with head%
  28. ' head% may not neccessarily be the actual head of the list.
  29. ' This feature is useful in "smart" searches
  30.  
  31.     STATIC Ptr%,Go.On%
  32.     
  33.     Found%=0
  34.     Ptr%=head%
  35.     Go.On%=1
  36.     
  37.     WHILE (Ptr%<>0) AND (Go.On%=1)
  38.         IF ListItem$(Ptr%)>=Item$ THEN
  39.             Go.On%=0
  40.         ELSE
  41.             Ptr%=ListPtr%(Ptr%)
  42.         END IF
  43.     WEND
  44.     
  45.     IF Ptr%<>0 THEN
  46.         IF ListItem$(Ptr%)=Item$ THEN Found%=1
  47.     END IF
  48. END SUB
  49.  
  50. REM InsertNode
  51. SUB InsertNode(Item$,head%,ListSize%,ListItem$(1),ListPtr%(1))
  52. ' insert Item$ in list ListItem$()
  53.  
  54.     STATIC Ptr%,LastPtr%,Go.On%
  55.     
  56.     IF (head%=0) OR (ListSize%=0) THEN
  57.         ListSize%=1
  58.         head%=1
  59.         ListItem$(1)=Item$
  60.         ListPtr%(1)=0
  61.     ELSE
  62.         LastPtr%=0
  63.         Ptr%=head%
  64.         Go.On%=1
  65.         
  66.         WHILE (Ptr%<>0) AND (Go.On%=1)
  67.             IF ListItem$(Ptr%)>=Item$ THEN
  68.                 Go.On%=0
  69.             ELSE
  70.                 LastPtr%=Ptr%
  71.                 Ptr%=ListPtr%(Ptr%)
  72.             END IF
  73.         WEND
  74.         
  75.         INCR ListSize%
  76.         ListItem$(ListSize%)=Item$
  77.         IF LastPtr%=0 THEN
  78.             ListPtr%(ListSize%)=Ptr%
  79.             head%=ListSize%
  80.         ELSE
  81.             ListPtr%(LastPtr%)=ListSize%
  82.             ListPtr%(ListSize%)=Ptr%
  83.         END IF
  84.     END IF
  85. END SUB
  86.  
  87. REM DelNode
  88. SUB DelNode(Item$,OK%,head%,ListSize%,ListItem$(1),ListPtr%(1))
  89. ' routine to delete node containing Item$
  90.  
  91.     STATIC Ptr%,LastPtr%,Go.On%
  92.     
  93.     OK%=0
  94.     LastPtr%=0
  95.     Ptr%=head%
  96.     Go.On%=1
  97.     
  98.     WHILE (Ptr%<>0) AND (Go.On%=1)
  99.         IF ListItem$(Ptr%)>=Item$ THEN
  100.             Go.On%=0
  101.         ELSE
  102.             LastPtr%=Ptr%
  103.             Ptr%=ListPtr%(Ptr%)
  104.         END IF
  105.     WEND
  106.     
  107.     IF Ptr%<>0 THEN
  108.         IF ListItem$(Ptr%)=Item$ THEN OK%=1
  109.     END IF
  110.     
  111.     IF OK%=1 THEN
  112.         IF LastPtr%=0 THEN
  113.             head%=ListPtr%(Ptr%)
  114.         ELSE
  115.             ListPtr%(LastPtr%)=ListPtr%(Ptr%)
  116.         END IF
  117.     END IF
  118.     
  119.     DECR ListSize%
  120. END SUB
  121.